// router/index.js
import { createRouter, createWebHashHistory } from "vue-router";
import { useStore } from "../store";
import NProgress from "nprogress";
export const routes = [
  {
    path: "/login",
    name: "login",
    component: () => import("../view/Login.vue"), //登录页
    title: "登录",
    meta: {
      // ignoreShowHeader: true
      title: "登录",
    },
  },
  {
    path: "/",
    name: "index",
    component: () => import("../view/Index.vue"), //登录页
    title: "首页",
    meta: {
      // ignoreShowHeader: true
      showInLeft: true,
      title: "首页",
    },
  },

  {
    path: "/progress",
    name: "progress",
    title: "应聘进度",
    component: () => import("../view/Progress.vue"),
    meta: {
      showInRight: true,
      title: "应聘进度",
      bgwhite: true, //头部背景白色
    },
  },
  {
    path: "/privacy",
    name: "privacy",
    title: "隐私政策",
    component: () => import("../view/Privacy.vue"),
    meta: {
      showInRight: true,
      title: "隐私政策",
      bgwhite: true, //头部背景白色
    },
  },
  // {
  //     path: '/userCenter',
  //     name: 'userCenter',
  //     title: "用户中心",
  //     component: () => import('../view/UserCenter.vue'), // 用户中心
  // },
  {
    path: "/join",
    name: "join",
    title: "简历投递",
    component: () => import("../view/join/Join.vue"), // 简历投递
    meta: {
      showInLeft: true,
      title: "简历投递",
      bgwhite: true, //头部背景白色
    },
  },
  {
    path: "/SureJoin",
    name: "SureJoin",
    title: "参训确认",
    component: () => import("../view/join/SureJoin.vue"), // 参训确认
    meta: {
      //showInLeft: true,
      title: "参训确认",
      bgwhite: true, //头部背景白色
    },
  },
  {
    path: "/VolChoice",
    name: "VolChoice",
    title: "志愿选择",
    component: () => import("../view/join/VolChoice.vue"), // 志愿选择
    meta: {
      //showInLeft: true,
      title: "志愿选择",
    },
  },
  {
    path: "/volResult",
    name: "volResult",
    title: "志愿选择结果页",
    component: () => import("../view/join/VolResult.vue"), // 志愿选择
    meta: {
      //showInLeft: true,
      title: "志愿选择结果页",
      bgwhite: true, //头部背景白色
    },
  },
  {
    path: "/delivered",
    name: "delivered",
    title: "已投递",
    component: () => import("../view/join/Delivered.vue"), // 志愿选择
    meta: {
      //showInLeft: true,
      title: "已投递",
      bgwhite: true, //头部背景白色
    },
  },
  {
    path: "/test",
    name: "test",
    title: "test",
    component: () => import("../view/test.vue"), // 志愿选择
    meta: {
      //showInLeft: true,
      title: "test",
    },
  },

  {
    path: "/share",
    name: "share",
    title: "分享好友",
    meta: {
      //showInLeft: true,
      bgwhite: true, //头部背景白色
      title: "分享好友",
    },
    component: () => import("../view/Share.vue"),
  },
  {
    path: "/contract",
    name: "contract",
    component: () => import("../view/Contract.vue"),
    meta: {
      //showInLeft: true,
      title: "应约协议",
      bgwhite: true, //头部背景白色
    },
  },
  {
    path: "/train",
    redirect: "/train/index",
    title: "培训信息",
    // 培训信息
    children: [
      {
        path: "/train/index",
        meta: {
          title: "培训信息",
        },
        component: () => import("../view/train/index.vue"),
      },
      {
        path: "/train/agreement",
        meta: {
          title: "培训协议",
          bgwhite: true, //头部背景白色
        },
        component: () => import("../view/train/trainAgreement.vue"),
      },
      {
        path: "/train/meals",
        title: "饮食调查",
        meta: {
          bgwhite: true, //头部背景白色
          title: "饮食调查",
        },
        component: () => import("../view/train/meals.vue"),
      },
      {
        path: "/train/expenseIntro",
        title: "报销协议",
        meta: {
          bgwhite: true, //头部背景白色
          title: "报销协议",
        },
        component: () => import("../view/train/expenseIntro.vue"),
      },
      {
        path: "/train/imgprivew",
        name: "images",
        title: "images",
        component: () => import("../view/train/imgprivew.vue"), // 志愿选择
        meta: {
          bgwhite: true, //头部背景白色
          title: "协议预览",
        },
      },
      {
        path: "/train/sanfang",
        name: "sanfang",
        title: "sanfang",
        component: () => import("../view/train/sanfang.vue"), // 志愿选择
        meta: {
          bgwhite: true, //头部背景白色
          title: "三方预览",
        },
      },
    ],
  },
];
const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

router.beforeEach((to, from, next) => {
  NProgress.configure({ showSpinner: false });
  NProgress.start();
  const store = useStore();
  const { hasLogin } = store;
  document.title = String(to.meta.title + " | 方田校招") || "HR管理系统";
  next();
  return;
  if (hasLogin || to.path == "/login") {
    next();
    return;
  } else {
    next({
      path: "/login",
    });
  }
});
router.afterEach(() => {
  NProgress.done();
});

export default router;
